package com.use.utils.demo;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

public class CreateBigFile {
    public static void main(String[] args) {
        // 本地保存路径
        String localSavePath = "/Users/a123456/Downloads/bigFIle.bin";

        // 文件大小（20GB）
        long fileSize = 5L * 1024 * 1024 * 1024;

        // 缓冲区大小（1MB）
        int bufferSize = 1024 * 1024;
        byte[] buffer = new byte[bufferSize];

        try (OutputStream outputStream = new FileOutputStream(localSavePath)) {
            long bytesWritten = 0;
            while (bytesWritten < fileSize) {
                int bytesToWrite = (int) Math.min(bufferSize, fileSize - bytesWritten);
                outputStream.write(buffer, 0, bytesToWrite);
                bytesWritten += bytesToWrite;
            }
            System.out.println("文件生成成功！");
        } catch (IOException e) {
            e.printStackTrace();
            System.out.println("生成文件时出错！");
        }
    }

}
